<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>访问json数据</title>
</head>
<body>
  <script type="text/javascript">
    if (window.XMLHttpRequest) {
      const xhr = new XMLHttpRequest();
      var url = "handler";
      xhr.open("GET", url, false);
      xhr.send();
      var body = document.getElementsByTagName("body")[0];
      if (xhr.readyState === 4 && xhr.status === 200) {
        body.innerHTML = body.innerHTML + "遍历对象的属性<br>";
        var span = document.createElement("span");
        body.appendChild(span);
        var object = JSON.parse(xhr.responseText);
        for (const key in object) {
          if (object.hasOwnProperty(key)) {
            span.append(key + "：" + object[key]);
            span.appendChild(document.createElement("br"));
          }
        }
      }
    } else
      alert("你的浏览器不支持XMLHttpRequest");
  </script>
</body>
</html>